.class public abstract Lcom/xiaomi/common/BasicVersionChecker;
.super Ljava/lang/Object;
.source "BasicVersionChecker.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;
    }
.end annotation


# static fields
.field private static final LOG_TAG:Ljava/lang/String; = "common/BasicVersionChecker"

.field public static final TextKey_ProgressDialog_Downloading:I = 0xb

.field public static final TextKey_Result_FailedToUpgrade:I = 0xc

.field public static final TextKey_UpgradePromptDialog_Detail:I = 0x2

.field public static final TextKey_UpgradePromptDialog_NoButton:I = 0x4

.field public static final TextKey_UpgradePromptDialog_Title:I = 0x1

.field public static final TextKey_UpgradePromptDialog_YesButton:I = 0x3


# instance fields
.field protected mRemoteAppVersion:I


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 35
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 39
    const/4 v0, -0x1

    iput v0, p0, Lcom/xiaomi/common/BasicVersionChecker;->mRemoteAppVersion:I

    .line 35
    return-void
.end method

.method static synthetic access$0(Lcom/xiaomi/common/BasicVersionChecker;Landroid/content/Context;)V
    .locals 0
    .parameter
    .parameter

    .prologue
    .line 176
    invoke-direct {p0, p1}, Lcom/xiaomi/common/BasicVersionChecker;->startDownload(Landroid/content/Context;)V

    return-void
.end method

.method private getInfoView(Landroid/content/Context;)Landroid/view/View;
    .locals 4
    .parameter "context"

    .prologue
    const/4 v3, 0x0

    .line 96
    new-instance v0, Landroid/widget/TextView;

    invoke-direct {v0, p1}, Landroid/widget/TextView;-><init>(Landroid/content/Context;)V

    .line 97
    .local v0, lInfoView:Landroid/widget/TextView;
    const/high16 v1, 0x4170

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setTextSize(F)V

    .line 98
    invoke-virtual {v0, v3}, Landroid/widget/TextView;->setBackgroundColor(I)V

    .line 99
    invoke-static {}, Landroid/text/method/ScrollingMovementMethod;->getInstance()Landroid/text/method/MovementMethod;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setMovementMethod(Landroid/text/method/MovementMethod;)V

    .line 100
    const/16 v1, 0xc8

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setMaxHeight(I)V

    .line 102
    const/16 v1, 0x14

    const/16 v2, 0xa

    invoke-virtual {v0, v1, v3, v2, v3}, Landroid/widget/TextView;->setPadding(IIII)V

    .line 103
    invoke-virtual {p0, p1}, Lcom/xiaomi/common/BasicVersionChecker;->getUpgradeMessage(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

    .line 104
    const/4 v1, -0x1

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setTextColor(I)V

    .line 105
    return-object v0
.end method

.method private static getPackageInfo(Landroid/content/Context;)Landroid/content/pm/PackageInfo;
    .locals 5
    .parameter "context"

    .prologue
    .line 218
    const/4 v1, 0x0

    .line 220
    .local v1, pInfo:Landroid/content/pm/PackageInfo;
    :try_start_0
    invoke-virtual {p0}, Landroid/content/Context;->getPackageManager()Landroid/content/pm/PackageManager;

    move-result-object v2

    invoke-virtual {p0}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v3

    const/16 v4, 0x80

    invoke-virtual {v2, v3, v4}, Landroid/content/pm/PackageManager;->getPackageInfo(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
    :try_end_0
    .catch Landroid/content/pm/PackageManager$NameNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 225
    :goto_0
    return-object v1

    .line 221
    :catch_0
    move-exception v2

    move-object v0, v2

    .line 222
    .local v0, e:Landroid/content/pm/PackageManager$NameNotFoundException;
    const-string v2, "common/BasicVersionChecker"

    invoke-virtual {v0}, Landroid/content/pm/PackageManager$NameNotFoundException;->getMessage()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_0
.end method

.method private startDownload(Landroid/content/Context;)V
    .locals 9
    .parameter "context"

    .prologue
    const/4 v3, 0x1

    .line 178
    .line 179
    const-string v0, ""

    .line 180
    const/16 v1, 0xb

    invoke-virtual {p0, v1}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v1

    .line 177
    invoke-static {p1, v0, v1, v3}, Landroid/app/ProgressDialog;->show(Landroid/content/Context;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Z)Landroid/app/ProgressDialog;

    move-result-object v2

    .line 183
    .local v2, progressDialog:Landroid/app/ProgressDialog;
    const/4 v8, 0x0

    .line 184
    .local v8, output:Ljava/io/FileOutputStream;
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-virtual {p1}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, ".apk"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    .line 186
    .local v4, localFileName:Ljava/lang/String;
    const/4 v0, 0x1

    :try_start_0
    invoke-virtual {p1, v4, v0}, Landroid/content/Context;->openFileOutput(Ljava/lang/String;I)Ljava/io/FileOutputStream;
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v8

    .line 191
    :goto_0
    if-eqz v8, :cond_0

    .line 192
    const/16 v0, 0xc

    invoke-virtual {p0, v0}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v5

    .line 193
    .local v5, failedText:Ljava/lang/CharSequence;
    iget v0, p0, Lcom/xiaomi/common/BasicVersionChecker;->mRemoteAppVersion:I

    invoke-virtual {p0, v0}, Lcom/xiaomi/common/BasicVersionChecker;->getRemoteApkFileUrl(I)Ljava/lang/String;

    move-result-object v6

    .line 197
    .local v6, downloadUrl:Ljava/lang/String;
    new-instance v0, Lcom/xiaomi/common/BasicVersionChecker$3;

    move-object v1, p0

    move-object v3, p1

    invoke-direct/range {v0 .. v5}, Lcom/xiaomi/common/BasicVersionChecker$3;-><init>(Lcom/xiaomi/common/BasicVersionChecker;Landroid/app/ProgressDialog;Landroid/content/Context;Ljava/lang/String;Ljava/lang/CharSequence;)V

    .line 194
    invoke-static {v6, v8, v0}, Lcom/xiaomi/common/Network;->beginDownloadFile(Ljava/lang/String;Ljava/io/OutputStream;Lcom/xiaomi/common/Network$PostDownloadHandler;)V

    .line 214
    .end local v5           #failedText:Ljava/lang/CharSequence;
    .end local v6           #downloadUrl:Ljava/lang/String;
    :cond_0
    return-void

    .line 187
    :catch_0
    move-exception v7

    .line 188
    .local v7, e1:Ljava/io/FileNotFoundException;
    invoke-virtual {v7}, Ljava/io/FileNotFoundException;->printStackTrace()V

    goto :goto_0
.end method


# virtual methods
.method public checkNewVersion(Landroid/content/Context;)Z
    .locals 6
    .parameter "context"

    .prologue
    const-string v5, "common/BasicVersionChecker"

    .line 49
    :try_start_0
    new-instance v3, Ljava/net/URL;

    invoke-virtual {p0}, Lcom/xiaomi/common/BasicVersionChecker;->getVersionableFileUrl()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-static {p1, v3}, Lcom/xiaomi/common/Network;->downloadXml(Landroid/content/Context;Ljava/net/URL;)Ljava/lang/String;

    move-result-object v2

    .line 50
    .local v2, xml:Ljava/lang/String;
    invoke-static {v2}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v3

    if-nez v3, :cond_0

    .line 51
    new-instance v1, Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;

    invoke-direct {v1}, Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;-><init>()V

    .line 52
    .local v1, remoteVersion:Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;
    invoke-virtual {v1, v2}, Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;->parseXML(Ljava/lang/String;)V

    .line 53
    invoke-virtual {v1}, Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;->getAppVersion()I

    move-result v3

    iput v3, p0, Lcom/xiaomi/common/BasicVersionChecker;->mRemoteAppVersion:I
    :try_end_0
    .catch Ljava/net/MalformedURLException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1

    .line 62
    .end local v1           #remoteVersion:Lcom/xiaomi/common/BasicVersionChecker$RemoteVersionParser;
    .end local v2           #xml:Ljava/lang/String;
    :cond_0
    :goto_0
    const/4 v3, 0x1

    :goto_1
    return v3

    .line 55
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 56
    .local v0, e:Ljava/net/MalformedURLException;
    const-string v3, "common/BasicVersionChecker"

    const-string v3, "error in url..."

    invoke-static {v5, v3, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0

    .line 57
    .end local v0           #e:Ljava/net/MalformedURLException;
    :catch_1
    move-exception v3

    move-object v0, v3

    .line 58
    .local v0, e:Ljava/io/IOException;
    const-string v3, "common/BasicVersionChecker"

    const-string v3, "error in downloading..."

    invoke-static {v5, v3, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    .line 59
    const/4 v3, 0x0

    goto :goto_1
.end method

.method public abstract getLocalizedText(I)Ljava/lang/CharSequence;
.end method

.method public abstract getRemoteApkFileUrl(I)Ljava/lang/String;
.end method

.method public getUpgradeMessage(Landroid/content/Context;)Ljava/lang/String;
    .locals 4
    .parameter "context"

    .prologue
    const-string v3, "common/BasicVersionChecker"

    .line 115
    iget v2, p0, Lcom/xiaomi/common/BasicVersionChecker;->mRemoteAppVersion:I

    invoke-virtual {p0, v2}, Lcom/xiaomi/common/BasicVersionChecker;->getUpgradeMessageFile(I)Ljava/lang/String;

    move-result-object v1

    .line 116
    .local v1, lFileUrl:Ljava/lang/String;
    invoke-static {v1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v2

    if-nez v2, :cond_0

    .line 119
    :try_start_0
    new-instance v2, Ljava/net/URL;

    invoke-direct {v2, v1}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-static {p1, v2}, Lcom/xiaomi/common/Network;->downloadXml(Landroid/content/Context;Ljava/net/URL;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/net/MalformedURLException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1

    move-result-object v2

    .line 127
    :goto_0
    return-object v2

    .line 120
    :catch_0
    move-exception v2

    move-object v0, v2

    .line 121
    .local v0, e:Ljava/net/MalformedURLException;
    const-string v2, "common/BasicVersionChecker"

    const-string v2, "error in url..."

    invoke-static {v3, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    .line 127
    .end local v0           #e:Ljava/net/MalformedURLException;
    :cond_0
    :goto_1
    const-string v2, ""

    goto :goto_0

    .line 122
    :catch_1
    move-exception v2

    move-object v0, v2

    .line 123
    .local v0, e:Ljava/io/IOException;
    const-string v2, "common/BasicVersionChecker"

    const-string v2, "error in downloading..."

    invoke-static {v3, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_1
.end method

.method public getUpgradeMessageFile(I)Ljava/lang/String;
    .locals 1
    .parameter "remoteVersion"

    .prologue
    .line 139
    const/4 v0, 0x0

    return-object v0
.end method

.method public abstract getVersionableFileUrl()Ljava/lang/String;
.end method

.method public hasNewAppVersion(Landroid/content/Context;)Z
    .locals 3
    .parameter "context"

    .prologue
    .line 66
    invoke-static {p1}, Lcom/xiaomi/common/BasicVersionChecker;->getPackageInfo(Landroid/content/Context;)Landroid/content/pm/PackageInfo;

    move-result-object v0

    .line 67
    .local v0, info:Landroid/content/pm/PackageInfo;
    if-eqz v0, :cond_0

    iget v1, v0, Landroid/content/pm/PackageInfo;->versionCode:I

    iget v2, p0, Lcom/xiaomi/common/BasicVersionChecker;->mRemoteAppVersion:I

    if-ge v1, v2, :cond_0

    const/4 v1, 0x1

    :goto_0
    return v1

    :cond_0
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public startUpgrade(Landroid/content/Context;)V
    .locals 3
    .parameter "context"

    .prologue
    .line 76
    new-instance v0, Landroid/app/AlertDialog$Builder;

    invoke-direct {v0, p1}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V

    .line 77
    invoke-direct {p0, p1}, Lcom/xiaomi/common/BasicVersionChecker;->getInfoView(Landroid/content/Context;)Landroid/view/View;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setView(Landroid/view/View;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    .line 78
    const/4 v1, 0x1

    invoke-virtual {p0, v1}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    .line 79
    const/4 v1, 0x2

    invoke-virtual {p0, v1}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    .line 80
    const/4 v1, 0x3

    invoke-virtual {p0, v1}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v1

    new-instance v2, Lcom/xiaomi/common/BasicVersionChecker$1;

    invoke-direct {v2, p0, p1}, Lcom/xiaomi/common/BasicVersionChecker$1;-><init>(Lcom/xiaomi/common/BasicVersionChecker;Landroid/content/Context;)V

    invoke-virtual {v0, v1, v2}, Landroid/app/AlertDialog$Builder;->setPositiveButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    .line 85
    const/4 v1, 0x4

    invoke-virtual {p0, v1}, Lcom/xiaomi/common/BasicVersionChecker;->getLocalizedText(I)Ljava/lang/CharSequence;

    move-result-object v1

    new-instance v2, Lcom/xiaomi/common/BasicVersionChecker$2;

    invoke-direct {v2, p0}, Lcom/xiaomi/common/BasicVersionChecker$2;-><init>(Lcom/xiaomi/common/BasicVersionChecker;)V

    invoke-virtual {v0, v1, v2}, Landroid/app/AlertDialog$Builder;->setNegativeButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    .line 90
    invoke-virtual {v0}, Landroid/app/AlertDialog$Builder;->create()Landroid/app/AlertDialog;

    move-result-object v0

    .line 91
    invoke-virtual {v0}, Landroid/app/AlertDialog;->show()V

    .line 92
    return-void
.end method
